/*class loginBox
 *
 *since version: 0.5
 *
 *page instance of loginBox
 *
 *
 *
 */
//instance
var loginBox = null;
function LoginBox()
{
    this.loginUsername = new DOMObject("loginUsername");
    this.loginPassword = new DOMObject("loginPassword");
    this.loginButton = new DOMObject("loginButton");
    this.loginRegist = new DOMObject("loginRegist");
    this.popupBox = new PopupBox("loginBox");
    this.width = 500;
    this.height= 400;
}
LoginBox.prototype.load = function()
{
    var This = this;
    var xhr = new XMLHttpRequest();
    xhr.open("GET",'loginBox.ajax',true)
    xhr.onreadystatechange = function()
    {
	if(xhr.readyState ==4)
	{
	    This.popupBox.html(xhr.responseText);
	    //404 handler at next version
	}
    }
    xhr.send();
}
LoginBox.prototype.show = function()
{
    var This = this;
    this.popupBox.popup();
    if(this.popupBox.innerHTMl == this.popupBox.defaultInnerHTML)
    {
	this.load();
    }
    this.initInteraction();
}
LoginBox.prototype.showoff = function()
{
    this.popupBox.popoff();
}

LoginBox.prototype.initInteraction = function()
{
    var This = this;
    if(this.loginButton.$())
    {
    	this.loginButton.$().onclick = bookLib.summitLogin;
	this.loginRegist.$().onclick = bookLib.showSignUpBox;
    }
    else
    {
	setTimeout(function(){This.initInteraction()},100);
    }
}
LoginBox.prototype.login = function()
{
    var username = this.loginUsername.$().value;
    var password = this.loginPassword.$().value;
    if(username==""||password=="")
    {
	Show("请输入登录信息");
	return false;
    }
    if(logger.login(username,password))
    {
	this.popupBox.popoff();
	defaultPage.manageStatus();
	Show("欢迎"+userManager.getClientInfo().username);
    }
    else
    {
	Show("登录失败请重试");
    }
}